# coding=utf-8
import MySQLdb


conn=MySQLdb.connect(host='localhost', user='root', passwd='', charset='utf8')
cursor = conn.cursor()
conn.select_db('test')
cursor.execute('DROP TABLE IF EXISTS testdb')
sql = """CREATE TABLE IF NOT EXISTS testdb(
            id int(11) AUTO_INCREMENT,
            a varchar(255),
            b varchar(255),
            c varchar(255),
            PRIMARY KEY (id)
      )ENGINE=InnoDB DEFAULT CHARSET=utf8"""

cursor.execute(sql)
conn.commit()

items = {
    'a':[1, 2, 3, 4],
    'b':[5, 6, 7, 8],
    'c':[9, 10, 11, 12],

}

for j in range(len(items['a'])):
    sql = """insert into testdb(a, b, c) values('%s','%s','%s')""" % (
            items['a'][j],
            items['b'][j],
            items['c'][j])
    cursor.execute(sql)
    conn.commit()

cursor.execute('select * from testdb')
for row in cursor.fetchall():
    print row

cursor.close()
conn.close()